//
//  GEProgressCollectionViewCell.m
//  ERP
//
//  Created by goldeney on 15/6/5.
//  Copyright (c) 2015年 ShangHai Goldeneye Techonology Co.,Ltd. All rights reserved.
//

#import "GEProgressCollectionViewCell.h"
#import "RTSpinKitView.h"
#import "NSDictionary+DataFormat.h"
#import "WebServiceCommonRequest.h"

@interface GEProgressCollectionViewCell()

@property (nonatomic, assign) BOOL isAlreadyGetData;

@end

@implementation GEProgressCollectionViewCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self){
        CGRect custom = self.contentView.frame;
        //custom.size.height = 240;
        self.frame = custom;
        
        // Initialization code
        RTSpinKitView *spinner = [[RTSpinKitView alloc] initWithStyle:RTSpinKitViewStyleFadingCircleAlt];
        spinner.center = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
        [spinner startAnimating];
        [self.contentView addSubview:spinner];
    }
    return self;
}

//获取网络数据
- (void)getNetWorkDataTableView:(UICollectionView*)collectionView moduleType:(NSString*)module parameter:(NSDictionary*)paramet index:(NSInteger)index
{
    //是否已经拉取过数据
    if (self.isAlreadyGetData) return;
    else self.isAlreadyGetData = YES;
    __weak __typeof(collectionView) weakSelf = collectionView;
    
    WebServiceCommonRequest *content = [[WebServiceCommonRequest alloc] init];
    [content setInterfaceType:InterfaceTypeGroup];
    [content setModuleType:module];
    [content setResultBackType:ResultBackTypeCommonUnordered];
    
    if (paramet)
        for(NSString *key in paramet){
            id value = [paramet objectFormatForKey:key];
            [content addParameterKey:key value:value];
        }
    
    [content startAsyncConnectCompleted:^(ServiceResultModel *result, NSDictionary *userInfo) {
        if(result.resultArray && result.resultArray.count>0){
            self.objectValue = result.resultArray;
            if (weakSelf) {
                __strong __typeof(weakSelf) strongSelf = weakSelf;
                NSIndexSet * sectionToReload = [[NSIndexSet alloc] initWithIndex:index];
                if (strongSelf) [strongSelf reloadSections:sectionToReload];
                //[strongSelf reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationLeft];
            }
        }
    } failed:^(NSError *error, NSDictionary *userInfo) {
        NSLog(@"==failed===%@",error);
    } abnormal:^(NSError *error, NSDictionary *userInfo) {
        NSLog(@"===abnormal==%@",error);
    }];
}

@end
